package com.xxq.semester.controller.exam;


import com.xxq.semester.entity.exam.ExamResources;
import com.xxq.semester.entity.ai.AiResources;
import com.xxq.semester.entity.utils.ResponseEntity;
import com.xxq.semester.service.ai.IAiResourcesService;
import com.xxq.semester.service.exam.IExamResourcesService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author saki
 * @since 2025-07-13
 */
@RestController
@RequestMapping("/api/exam-resources")
@Tag(name="考试资源管理", description="管理考试相关的资源，如试题、参考资料等")
public class ExamResourcesController {
    @Autowired
    private IExamResourcesService examResourcesService;

    @Autowired
    private IAiResourcesService aiResourcesService;


    @GetMapping("/list")
    @Operation(summary = "获取所有资源列表", description = "获取所有资源列表")
    public ResponseEntity<List<AiResources>> getResourcesList() {
        List<AiResources> list = aiResourcesService.listAll();
        return ResponseEntity.success(list);
    }

    /**
     * 选择资源并关联到考试
     */
//    @PostMapping("/select-resources")
//    public String selectResources(@RequestBody SelectResourcesRequest request) {
//        examResourcesService.saveSelectedResources(request.getExamId(), request.getResourceIds());
//        return "资源选择成功";
//    }
    @PostMapping("/select-resources")
    @Operation(summary = "选择资源并关联到考试", description = "选择资源并关联到考试")
    public ResponseEntity<String> selecctResources(@RequestBody SelectResourcesRequest request) {
        examResourcesService.saveSelectedResources(request.getExamId(), request.getResourceIds());
        return ResponseEntity.success("资源选择成功");
    }

    public static class SelectResourcesRequest {
        private Long examId;
        private List<Long> resourceIds;

        // getter和setter
        public Long getExamId() { return examId; }
        public void setExamId(Long examId) { this.examId = examId; }
        public List<Long> getResourceIds() { return resourceIds; }
        public void setResourceIds(List<Long> resourceIds) { this.resourceIds = resourceIds; }
    }
}
